package leetcode.code0563;

import leetcode.helper.tree.TreeNode;

public class Solution563_1 {

	public int findTilt(TreeNode root) {
		return this.find(root)[0];
	}

	private int[] find(TreeNode root) {
		if (root == null) {
			return new int[] { 0, 0 };
		}
		int[] left = this.find(root.left);
		int[] right = this.find(root.right);
		return new int[] { Math.abs(left[1] - right[1]) + left[0] + right[0], left[1] + right[1] + root.val };
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
